const redisConfig = require('../config/RedisConfig')
const DB = require('../config/Sequelize')
const BackCode = require("../utils/BackCode");
const CommentService = {
    page: async (req) => {
        const { page, size, id } = req.body;
        if (!page || !size || !id) {
            return BackCode.buildError({ msg: '参数错误' })
        }
        let {count, rows} = await DB.Comment.findAndCountAll({ 
            where: { product_id:id },
            offset: Number((page - 1) )* size,
            limit: Number(size),
            order: [['gmt_create', 'DESC']]
        })
        //计算总页数
        let total_page = Math.ceil(count / size)
        return BackCode.buildSuccessAndData({ data: {current_data: rows, total_page, total: count } })
    },
}
module.exports = CommentService